﻿namespace PicFingerprint
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using Util;

    class PicInfoCompareById : IComparer<PicInfo>
    {
        public int Compare(PicInfo lhs, PicInfo rhs)
        {
            return lhs.Id.CompareTo(rhs.Id);
        }
    }

    class PicInfo : IComparable<PicInfo>
    {
        internal bool InGroup { get; set; }

        internal int Id { get { return id; } }
        internal string Path { get { return path; } }
        internal int NumOnesInHashCode { get { return numOnesInHashCode; } }
        internal ulong PerceptionHashCode { get { return perceptionHashCode; } }

        private int id;  // Starts from 0
        private string path;
        private int numOnesInHashCode;
        private ulong perceptionHashCode;
        private int[] colorHistogramVector;

        public int CompareTo(PicInfo p)
        {
            return NumOnesInHashCode.CompareTo(p.NumOnesInHashCode);
        }

        /// <summary>
        /// Just used for constructing a comparator.
        /// </summary>
        internal PicInfo(int numOnes)
        {
            InGroup = false;
            id = -1;
            perceptionHashCode = 0;
            colorHistogramVector = null;
            path = "";
            numOnesInHashCode = numOnes;
        }

        internal PicInfo(int i, FileInfo f)
        {
            try
            {
                Image img = Image.FromFile(f.FullName);
                perceptionHashCode = ImageProcessor.GetPerceptionHashCode(img);
                colorHistogramVector = ImageProcessor.GetColorHistogramVector(img);
            }
            catch { throw; }

            InGroup = false;
            id = i;
            path = f.FullName;
            numOnesInHashCode = NumberHacking.GetNumOnes(perceptionHashCode);
        }
    }
}
